/**
 * 
 */
package com.java.test.user.mapper;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Component;

import com.java.test.user.dto.IpcheckInfo;
import com.java.test.util.PageInfo;

/**
 * @author Administrator
 *
 */
@Component
public class IpcheckInfomMapper {
	@Autowired
	private JdbcTemplate jdbcTemplate;

	public int selectIpCheckByTimeCount(IpcheckInfo info) {
		String sql = "select count(*) from member_ip_check where 1=1 ";
		
		if (info.getUseTime() != null && !"".equals(info.getUseTime())) {
			sql += " and TO_DAYS(use_time)= TO_DAYS('" + info.getUseTime() + "')";
		}
		if (info.getAccountNo() != null && !"".equals(info.getAccountNo())) {
			sql += " and account_no like  '%" + info.getAccountNo() + "%'";
		}

		Integer i = jdbcTemplate.queryForObject(sql, Integer.class);

		return i == null ? null : i;
	}

	public List<IpcheckInfo> selectIpCheckByTimeList(IpcheckInfo info, PageInfo<IpcheckInfo> page) {
		String sql = "select * from member_ip_check where 1=1 ";

		
		if (info.getUseTime() != null && !"".equals(info.getUseTime())) {
			sql += " and TO_DAYS(use_time)= TO_DAYS('" + info.getUseTime() + "')";
		}
		if (info.getAccountNo() != null && !"".equals(info.getAccountNo())) {
			sql += " and account_no like  '%" + info.getAccountNo() + "%'";
		}
		int start = (page.getCurrentPage() - 1) * page.getPageCount();
		int limit = page.getPageCount();

		sql += "limit ?,?";
		List<IpcheckInfo> list = jdbcTemplate.query(sql, new IpcheckInfo(), start, limit);

		return list;
	}

	public int updateBlackStatus(IpcheckInfo info) {
		String sql = "update member_ip_check set account_status=? where id=?";
		int i = jdbcTemplate.update(sql, info.getAccountStatus(), info.getId());
		return i;
	}

}
